<template>
	<view class="">
		<view class="headTop">
			<view class="text-center wode text-bold text-black">我的</view>
			<view class=" u-flex u-p-l-30 u-p-t-30 u-p-b-30">
				<view class="u-m-r-10">
					<image :src="avatar" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;"
						@click="goNavs('/pages/my/userinfo')"></image>
				</view>
				<view class="u-m-l-10 text-white margin-left-sm" v-if="!isLogin">
					<view class=" u-font-18  text-bold" @click="goNavs('/pages/my/userinfo')">{{userName}}</view>
					<view class="" v-if="XCXIsSelect != '否'">
						<view v-if="Qe == 0" class="round u-font-12" @click.stop="goNav('/my/renzheng/index')"
							style="color: #666666;font-weight: 400;">
							未入驻
						</view>
						<view v-else-if="Qe == 1" class="round u-font-12" style="color: #666666;font-weight: 400;"
							@click.stop="goNav('/my/renzheng/index')">
							审核中
						</view>
						<view v-else-if="Qe == 2" class="round u-font-12" style="color: #666666;font-weight: 400;"
							@click.stop="goNav('/my/renzheng/index')">
							已入驻
						</view>
						<view v-else-if="Qe == 3" class="round u-font-12" style="color: #666666;font-weight: 400;"
							@click.stop="goNav('/my/renzheng/index')">
							已拒绝
						</view>
					</view>
				</view>
				<view v-else class="text-xl u-p-l-20 text-bold" @click="goLogin('/pages/public/login')">
					登录
				</view>
			</view>
		</view>


		<view class="bg radius margin padding">
			<!-- <view>我的交易</view> -->
			<view class="flex justify-between padding-lr-xs margin-top-sm">
				<view class="text-center" @click="goNav('/my/takeOrder/index')" style="position: relative;">
					<image src="../../static/images/my/order1.png" style="width: 60upx;height: 60upx;"></image>
					<view>我的接单</view>
					<view class="weidu" v-if="waitService != 0">
						{{waitService}}
					</view>
				</view>
				<view class="text-center" @click="goNav('/my/publish/index')">
					<image src="../../static/images/my/order2.png" style="width: 60upx;height: 60upx;"></image>
					<view>服务上架</view>
				</view>
				<view class="text-center" @click="goNav('/my/order/index')" style="position: relative;">
					<image src="../../static/images/my/order3.png" style="width: 60upx;height: 60upx;"></image>
					<view>服务订单</view>
					<view class="weidu" v-if="serviceCount != 0">
						{{serviceCount}}
					</view>
				</view>
			</view>
		</view>
		<view class="bg margin radius">
			<!-- 员工管理 -->
			<!-- {{XCXIsSelect != '否'&&Qe==2}} -->
			<view class="flex padding-lr padding-tb dfs" @click="goNavs('/work/index/index')"
				v-if="XCXIsSelect != '否'&&Qe==2">
				<image src="../../static/images/my/yuangong.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">员工管理</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 时间管理 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNavs('/my/data/index')" v-if="XCXIsSelect != '否'">
				<image src="../../static/images/my/data.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">时间管理</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>

			<!-- 我的报价-->
			<view class="flex padding-lr padding-tb dfs" @click="goNavs('/my/takeOrder/baojia')"
				v-if="XCXIsSelect != '否'">
				<image src="../../static/images/my/baijia.png" style="width: 48upx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">我的报价</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 店铺信息 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNavs('/pages/my/userinfo')"
				v-if="XCXIsSelect != '否'">
				<image src="../../static/images/my/dianpu.png" style="width: 50rpx;height: 45rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">店铺信息</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 保证金 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNavs('/my/wallet/baozhengjin')"
				v-if="XCXIsSelect != '否'&&baozhengjin!=0">
				<image src="../../static/images/my/baozhengjin.png" style="width: 54rpx;height: 54rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">保证金</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 我的钱包 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNav('/my/wallet/index')" v-if="XCXIsSelect != '否'">
				<image src="../../static/images/my/qianbao.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">我的钱包</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 帮助中心 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNav('/my/feedbackIndex/feedbackIndex')">
				<image src="../../static/images/my/help.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">帮助中心</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 意见反馈 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNav('/my/feedback/index')">
				<image src="../../static/images/my/yijian.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">意见反馈</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 在线客服 @click="goNav(list[4].url)"-->
			<view class="flex padding-lr padding-tb" @click="goChat()">
				<image src="../../static/images/my/kefu.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">在线客服</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
			<!-- 设置中心 -->
			<view class="flex padding-lr padding-tb dfs" @click="goNav('/my/setting/index')">
				<image src="../../static/images/my/set.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">设置中心</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
		</view>
		
		<view class="bg margin radius">
			<!-- 员工管理 -->
			<!-- {{XCXIsSelect != '否'&&Qe==2}} -->
			<view class="flex padding-lr padding-tb dfs" @click="goUserClient()">
				<image src="../../static/images/my/user-client.png" style="width: 50rpx;height: 50rpx;" mode=""></image>
				<view class="flex-sub margin-left text-df" style="line-height: 50upx;">我要下单找师傅</view>
				<image src="../../static/images/my/right.png" class="images" mode=""></image>
			</view>
		</view>
		
		<view  style="height: 50rpx;" />
		
		<!-- </view> -->

	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '../../static/logo.png',
				isLogin: true,
				userName: '匿名',
				browse: 0, //浏览数
				fans: 0, //粉丝数
				follow: 0, //关注数
				visitor: 0, //访客数
				userId: '',
				isVip: false,
				invitationCode: '', //邀请码
				geRen: 0,
				Qe: 0,
				XCXIsSelect: '否',
				renzheng: false,
				classify: 1,
				userId: '',
				arr: [],
				showModal: true,
				isAuthentication: '',
				baozhengjin: 0,
				waitService: 0,
				serviceCount: 0
			}
		},
		onLoad() {
			this.XCXIsSelect = this.$queue.getData("XCXIsSelect");
			this.classify = uni.getStorageSync("classify") ? uni.getStorageSync("classify") : '1'

			this.userId = uni.getStorageSync('userId')




			if (this.userId) {


				this.$Request.getT('/app/common/type/235').then(res => { //新订单通知
					if (res.code == 0) {
						if (res.data && res.data.value) {
							this.arr.push(res.data.value)
						}
					}
				})
				this.$Request.getT('/app/common/type/261').then(res => { //商家私聊消息通知
					if (res.code == 0) {
						if (res.data && res.data.value) {
							this.arr.push(res.data.value)
						}
					}
				})

				// 商家端订单状态通知	623
				this.$Request.getT('/app/common/type/623').then(res => { //商家端订单状态通知
					if (res.code == 0) {
						if (res.data && res.data.value) {
							this.arr.push(res.data.value)
						}
					}
				})

			}

			this.$Request.get("/app/common/type/616").then(res => {
				if (res.code == 0 && res.data) {
					this.baozhengjin = res.data.value
				} else {
					this.baozhengjin = 0
				}
			});
		},
		onShow() {
			if (this.userId) {
				// 获取待服务订单的数量
				let a = {
					userId: this.userId
				}
				this.$Request.get('/app/help/selectWaitServiceOrderCount', a).then(res => {
					if (res.code == 0) {
						this.waitService = res.data.waitService;
						this.serviceCount = res.data.serviceCount;
					}
				})
			}
			this.Qe = uni.getStorageSync("Qe")
			this.userId = uni.getStorageSync('userId')
			if (this.userId) {
				this.isLogin = false
				this.getUserInfo()
				this.getRenZheng()
				this.getAmount()
				this.getIsVip()
			} else {
				this.isLogin = true
				this.userName = '匿名'
				this.browse = 0
				this.fans = 0
				this.follow = 0
				this.visitor = 0
				this.baozhengjin = 0
				this.avatar = '../../static/logo.png'
				// #ifdef MP-WEIXIN
				//订阅
				if (this.showModal) {
					this.openMsg()
				}
				// #endif
			}
			if (this.Qe == 2) {
				this.renzheng = false
			} else {
				this.renzheng = true
			}
		},
		methods: {
			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态，默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal = true
									}
								}
							})
						}
					}
				})
			},
			//微信填写能力获取头像
			onChooseAvatar(e) {
				console.log(e.detail.avatarUrl)
				let that = this;
				let token = uni.getStorageSync('token');
				uni.showLoading({
					title: '上传中...'
				});
				uni.uploadFile({
					// url: config.APIHOST1 + '/alioss/upload', //仅为示例，非真实的接口地址
					url: 'https://jiazhengshopv5.xianmaxiong.com/sqx_fast/alioss/upload', //仅为示例，非真实的接口地址
					filePath: e.detail.avatarUrl,
					// filePath: res.tempFilePaths[0],
					header: {
						token: token
					},
					name: 'file',
					success: uploadFileRes => {
						let url = JSON.parse(uploadFileRes.data).data;
						that.$Request.postJson(
							'/app/user/updateUserImageUrl?avatar=' + url).then(
							res => {
								uni.hideLoading();
								if (res.code === 0) {
									that.$queue.showToast(
										"更新成功");
									that.getUserInfo();
								}
							});
					}
				});

			},
			// 跳转商户端
			goshop() {
				wx.navigateToMiniProgram({
					appId: 'wxfe0e405895cafdf9',
					path: '',
					envVersion: 'release', // 打开正式版
					success(res) {
						// 打开成功
					},
					fail: function(err) {
						console.log(err);
					}
				})
			},
			goNav(e, name) {
				// #ifdef MP-WEIXIN
				wx.requestSubscribeMessage({
					tmplIds: this.arr,
					success(re) {
						console.log(JSON.stringify(re), 111111111111)
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							// console.log(re)
						}
					},
					fail: (res) => {
						// console.log(res)
					}
				})
				// #endif
				if (this.userId) {
					uni.navigateTo({
						url: e
					})

				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goChat() {
				let that = this
				let kefu = this.$queue.getData('kefu'); // 用户端联系方式 1 手机号 2企业微信 3 客服二维码  4在线客服
				let kefuPhone = this.$queue.getData('kefuPhone');
				if (kefu == 1) {
					uni.makePhoneCall({
						phoneNumber: kefuPhone //仅为示例
					});
				} else if (kefu == 3) { //客服二维码
					uni.navigateTo({
						url: '/my/setting/customer'
					});
				} else if (kefu == 2) {
					// #ifdef MP-WEIXIN
					try {
						wx.openCustomerServiceChat({
							extInfo: {
								url: that.$queue.getData('kefuUrl')
							},
							corpId: that.$queue.getData('kefuAppId'),
							success(res) {},
							fail(res) {
								console.error(res)
							}
						})
					} catch (error) {
						console.error("catchcatch" + error)
						uni.showToast({
							title: '请更新至微信最新版本'
						});
					}
					// #endif
					// #ifndef MP-WEIXIN
					let url = that.$queue.getData('kefuUrl');
					if (url.indexOf('/pages/') !== -1 || url.indexOf('/my/') !== -1) {
						uni.navigateTo({
							url
						});
					} else {
						//#ifndef H5
						uni.navigateTo({
							url: '/pages/index/webView?url=' + url
						});
						//#endif
						//#ifdef H5
						window.location.href = url;
						//#endif
					}
					// #endif

				} else if (kefu == 4) {
					let token = that.$queue.getData('token');
					if (token) {
						// #ifdef MP-WEIXIN
						wx.requestSubscribeMessage({
							tmplIds: that.arr,
							success(re) {
								var datas = JSON.stringify(re);
								if (datas.indexOf("accept") != -1) {
									// console.log(re)
								}
							},
							fail: (res) => {
								// console.log(res)
							}
						})
						// #endif
						uni.navigateTo({
							url: '/my/setting/chat'
						});
					} else {
						uni.showModal({
							title: '提示',
							content: '您还未登录,请先登录',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/pages/public/login'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}
				}
			},
			goNavs(e, name) {
				let that = this
				// #ifdef MP-WEIXIN
				wx.requestSubscribeMessage({
					tmplIds: this.arr,
					success(re) {
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							// console.log(re)
						}
					},
					fail: (res) => {
						// console.log(res)
					}
				})
				// #endif
				if (this.userId) {
					if (this.Qe == 2) {
						uni.navigateTo({
							url: e
						})
					} else if (this.Qe == 1) {
						uni.showModal({
							title: '提示',
							content: '实名认证审核中,请稍等',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									// uni.navigateTo({
									// 	url: '/my/renzheng/index'
									// })
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					} else {
						uni.showModal({
							title: '提示',
							content: '您还未实名认证,请先认证',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/my/renzheng/index?classify=' + that.classify
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			goLogin(e) {
				// #ifdef MP-WEIXIN
				wx.requestSubscribeMessage({
					tmplIds: this.arr,
					success(re) {
						console.log(JSON.stringify(re), 111111111111)
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							// console.log(re)
						}
					},
					fail: (res) => {
						// console.log(res)
					}
				})
				// #endif
				uni.navigateTo({
					url: e
				})
			},
			getAmount() {
				this.$Request.get("/app/userBrowse/selectAmount").then(res => {
					if (res.code == 0) {
						this.browse = res.data.browse
						this.fans = res.data.fans
						this.follow = res.data.follow
						this.visitor = res.data.visitor
					}
				});
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.userName = res.data.userName
						this.invitationCode = res.data.invitationCode
						this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
						this.isAuthentication = res.data.isAuthentication

						uni.setStorageSync('isAuthentication', res.data.isAuthentication)
						uni.setStorageSync('isSafetyMoney', res.data.isSafetyMoney) //是否缴纳保证金 0否 1是
						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
						uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)

					}
				});
			},
			// 企业认证数据
			getRenZheng() {
				this.$Request.get("/app/userCertification/queryInsert").then(res => {
					console.log(res)
					if (res.code == 0) {
						if (res.data == null) { //未实名
							this.Qe = 0
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 0) { //审核中
							this.Qe = 1
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 1) { //已实名
							this.Qe = 2
							uni.setStorageSync("Qe", this.Qe)
						} else if (res.data.status == 2) { //已拒绝
							this.Qe = 3
							uni.setStorageSync("Qe", this.Qe)
						}
					}
				});
			},
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
						uni.setStorageSync('isVIP', res.data)
					}
				});
			},
			/**
			 * 跳转到用户端
			 */
			goUserClient(){
				let userAppId = this.$queue.getData('userAppId')
				//#ifdef MP-WEIXIN
				wx.navigateToMiniProgram({
					appId: userAppId,
					path: '/pages/index/index',
					envVersion: 'release', // 打开正式版
					success(res) {
						// 打开成功
					},
					fail: function(err) {
						console.log(err);
					}
				})
				// #endif 
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	button::after {
		border: none;
		background-color: none;
	}

	button {
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-decoration: none;
		line-height: 1.35;
		overflow: hidden;
		color: #666666;
		/* background-color: #fff; */
		background-color: rgba(255, 255, 255, 0) !important;
		width: 100%;
		height: 100%;
	}

	.bg {
		background: #FFFFFF;
	}

	.headTop {
		background: linear-gradient(0deg, rgba(255, 255, 255, 0) 0%, #557EFD 100%);
	}

	.wode {
		// color: #FFFFFF;
		height: 100upx;
		display: flex;
		align-items: flex-end;
		justify-content: center;
		/* #ifdef H5 */
		font-size: 16px;
		margin-top: -30upx;
		/* #endif */
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.btn-bg {
		width: 64px;
		height: 28px;
		background: linear-gradient(90deg, #CDA26E 0%, #DCB78A 100%);
		border-radius: 28px;
		text-align: center;
		line-height: 28px;
		margin-top: 4px;
		color: '#604320'
	}

	.images {
		width: 18rpx;
		height: 30rpx;
	}

	.dfs {
		display: flex;
		align-items: center;
	}

	.lovip {
		width: 100rpx;
		height: 35rpx;
		position: relative;
		top: -39rpx;
	}

	.weidu {
		background: red;
		display: inline-block;
		color: #FFFFFF;
		// padding: 4rpx 15rpx;
		padding: 0rpx 8rpx;
		border-radius: 48%;
		font-size: 24rpx;
		position: absolute;
		top: -10rpx;
		right: 20rpx;
	}
</style>